<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.yaodian100.core.common.utils.ServerValue"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ include file="/taglibs.jsp"%>
<!-- 月历 -->
<link rel="stylesheet" type="text/css" href="/css/smoothness.datepick.css" />
<link rel="stylesheet" type="text/css" media="screen" href="/css/ui.jqgrid.css" />
<link href="/css/ddaccordion.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick-zh-CN.js"></script>
<script src="/js/grid.locale-en.js" type="text/javascript"></script>
<script src="/js/jquery.jqGrid.min.js" type="text/javascript" charset="UTF-8"></script>
<s:url var="supplierPops" value="/json/supplierPops.do"/>
<s:url var="brandPops" value="/json/brandPops.do"/>
<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath()%>'/>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.alphanumeric.js"></script>
<script language="javascript">
	var content;
	var qry_target = '01';
	$().ready( function() {
		$("#shelfProductIdParam").numeric();
		$("#addonProductIdParam").numeric();
		$("#supplierIdParam").numeric();
		$("#getSupplier").click(function() {
			doAR('${supplierPops}', 'dialog'); 
			openDialog('供应商搜寻',content, 550, 440);
		});
		//$("#brandIdParam").numeric();
		$("#getBrand").click(function() {
			doAR('${brandPops}', 'dialog'); 
			openDialog('品牌搜寻',content, 550, 440);
		});	
		$('#startDateParam').datepick({minDate: new Date(${minDate}), maxDate:new Date(${today}),showOn:'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd"}); 
		$('#endDateParam').datepick({minDate: new Date(${minDate}), maxDate:new Date(${today}),beforeShow:customRange,showOn: 'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd"});
		$("#productForm").submit(function(){
			if ( 0 == $(":checkbox[name='prdtDelete']:checked").size() ){
				alert("请勾择要修改的商品");
				return false;
			} 
			if ( "" == $("#productAttribute").val() ){
				alert("请选择商品属性");
				return false;
			}
			return true;
		});		

		//load default value
		if ( "" != "${categoryLevel1Param}"){ 
			$('#elementSelect').find('option').remove().end();
			$("#categorySelect option[value='${categoryLevel1Param}']").attr('selected', 'selected');  
			$.post("${midContextPath}/category/getProductCategory.do",{categoryid:"${categoryLevel1Param}"},elementSelectCallback,"json");
		}
		
		$("#categorySelect").click(function(){
			if ( "" != $(this).val()  ){
				$.ajax({
				    url: '${midContextPath}/category/getProductCategory.do',
				    type: 'post',
				    dataType: 'json',
				    data: {categoryid:$(this).val(), callback: 'elementSelectCallback'},
				    cache: false,
				    beforeSend: function(xhr) {
							$('#elementSelect').find('option').remove().end();
				    },
				    complete:function(){
				    },
				    success: function( strData ){
				    	elementSelectCallback(strData);
					}
				});
			}
		});		
	});
	function elementSelectCallback(categories){
		$('#elementSelect').append($("<option></option>").attr("value","").text("--请选择--"));
		for( var i = 0 ; i < categories.length; i++ ){
				$('#elementSelect').append($("<option></option>").attr("value",categories[i].id).text(categories[i].name));
		}
		if ( "" != "${categoryLevel2Param}" )
			$("#elementSelect option[value='${categoryLevel2Param}']").attr('selected', 'selected');
	}	
	function customRange (){
		var startDt = $('#startDateParam').val(); //起始日
		var endDt = new Date(parseInt(startDt.substring(0,4),10),parseInt(startDt.substring(5,7),10)-1,parseInt(startDt.substring(8,10),10)); //結束日
		return {minDate:endDt,maxDate: new Date(${today})}; 
	}
</script>
<style type="text/css">
    .bg-active {
        background: #D4FAED;
    }
</style>
<h1>N选M商品管理<br/>
	<div class="f-link">
		<a href="editProduct.do?shelfIdParam=&productIdParam=">新增商品</a>
	</div>
</h1>
<s:actionerror />
<s:actionmessage />
<s:fielderror />
<br/>
<div class="data-form">
	<s:form action="search.do" method="post">
		<b>活动商品编号：</b>
		<input name="mainProductIdParam" id="shelfProductIdParam" type="text" title="活动商品编号" maxlength="8" value="${mainProductIdParam}">
		<b>活动商品名称关键字：</b>
		<input name="promoteNameParam" id="promoteNameParam" type="text" title="活动商品名称关键字" value="${promoteNameParam}">
		<b>销售状态：</b>
    <s:select name="productAttributeParam" list="attributeMenu.options" listKey="key"  listValue="value.name"/>
		<br/>
		<b>搭配商品编号:</b>
		<input name="addonProductIdParam" id="addonProductIdParam" type="text" title="搭配商品编号" value="${addonProductIdParam}">
		<b>活动起迄时间：</b>
		<input name="startDateParam" type="text" id="startDateParam" value="${startDateParam}" size="10" maxlength="10"> ~
    <input name="endDateParam" type="text" id="endDateParam" value="${endDateParam}" size="10" maxlength="10">
    <br/>
    <b>供应商编号：</b>
		<s:textfield name="supplierParam" id="supplierIdParam" maxlength="6"/>
		<img class="ui-icon ui-icon-search" src="/images/none.gif" style="height:16px; width:16px; position:relative; display:inline;" 
			id="getSupplier"/>
	<b>品牌编号：</b> 
	<s:textfield name="brandParam" id="brandIdParam" />
	<img class="ui-icon ui-icon-search" src="/images/none.gif" style="height:16px; width:16px; position:relative; display:inline;" 
		id="getBrand"/>  
  	<b>主要负责PM：</b>
  	<s:select id="pmParam" name="pmParam" list="users" listKey="username"  listValue="nameNative" headerKey="" headerValue="--请选择--"/>
		<b>PM所属单位：</b>
		<s:select id="organizationParam" name="organizationParam" list="groups" listKey="code"  listValue="description" headerKey="" headerValue="--请选择--"/>
		<br/>
		<b>馆别：</b>
		<select id="categorySelect" name="categoryLevel1Param">
				<option value="">--请选择--</option>
       	<c-rt:forEach items="${rootCategories}" var="category">
				<option value="${category.id}">${category.name}</option>
			</c-rt:forEach>
    </select>
    <select id="elementSelect" name="categoryLevel2Param">
    	<option value="">--请选择--</option>
    </select>      		
		<input type="button" value="搜寻" onclick="this.form.submit();" />
	</s:form>
</div>
<p></p>
<br/><br/><br/>
<s:form action="editProductAttribute.do" method="post" id="productForm">
	<table class="tb-1" width="100%">
		<thead>
			<tr>
	      <th>#</th>
	      <th>商品图片</th>
	      <th>商品编号</th>
	      <th>商品名称</th>
				<th>活动商品名称</th>
				<th>搭选商品数</th>
				<th>上架销售价格</th>
				<th>活动起迄时间</th>
				<th>销售状态</th>
				<th>上传图片</th>
				<th>任选维护</th>
				<th>上下架</th>
			</tr>
		</thead>
		<tbody>
				<c-rt:forEach items="${viewPickProducts}" var="viewPickProduct" varStatus="rows_index">  
				<tr class="${viewPickProduct.flag eq 'Y' and viewPickProduct.modifyDate eq viewPickProduct.maxDate? 'bg-active' : ''}">
	        <td><input name="prdtDelete" type="checkbox" value="${viewPickProduct.productId}" /></td>
	        <td><img onError="this.src='/PImg/blank_75.gif'" src="/PImg/${fn:substring(viewPickProduct.productId,0,4)}/${viewPickProduct.productId}/${viewPickProduct.productId}_m75.jpg"/></td>
	        <td><a href="<%=ServerValue.getMidContextPath()%>/pickProduct/editProduct.do?shelfIdParam=${viewPickProduct.shelfId}&productIdParam=${viewPickProduct.productId}" />${viewPickProduct.productId}</a></td>
	        <td>
	        	<c-rt:choose>
					   	<c-rt:when test="${fn:length(viewPickProduct.productName) > 18}">
					   		${fn:substring(viewPickProduct.productName,0,18)}...
					   	</c-rt:when>
					   	<c-rt:otherwise>${viewPickProduct.productName}</c-rt:otherwise>
					  </c-rt:choose>
	        </td>
					<td>
						<c-rt:choose>
					   	<c-rt:when test="${fn:length(viewPickProduct.promoteName) > 18}">
					   		${fn:substring(viewPickProduct.promoteName,0,18)}...
					   	</c-rt:when>
					   	<c-rt:otherwise>${viewPickProduct.promoteName}</c-rt:otherwise>
					  </c-rt:choose>
					</td>
					<td>${viewPickProduct.pickupQty }</td>
					<td><fmt:formatNumber value="${viewPickProduct.shelfPrice}" pattern="######.0"/></td>
					<td>
						<fmt:formatDate value="${viewPickProduct.startDate}" pattern="yyyy-MM-dd HH:mm" /> ~
						<fmt:formatDate value="${viewPickProduct.endDate}" pattern="yyyy-MM-dd HH:mm" />
					</td>
					<td>
						<c-rt:if test="${viewPickProduct.isDelete eq 'Y'}">已删除 (不可查询,不可销售)</c-rt:if>
						<c-rt:if test="${viewPickProduct.isDelete eq 'N'}">未删除 (可查询,可销售)</c-rt:if>
						<c-rt:if test="${viewPickProduct.isDelete eq 'Q'}">可查询,不可销售(Queryable)</c-rt:if>
						<c-rt:if test="${viewPickProduct.isDelete eq 'H'}">不可查询,可销售(Hidden)</c-rt:if>
					</td>
					<td>
						<a href="<%=ServerValue.getMidContextPath()%>/pickProduct/viewUploadProdImg.do?productIdParam=${viewPickProduct.productId}&shelfIdParam=${viewPickProduct.shelfId}">上传图片</a>
					</td>
					<td>
						<a href="<%=ServerValue.getMidContextPath()%>/pickProduct/editPickProduct.do?productIdParam=${viewPickProduct.productId}&shelfIdParam=${viewPickProduct.shelfId}">任选维护</a>
					</td>
					<td>
						<a href="<%=ServerValue.getMidContextPath()%>/pickProduct/editShelf.do?productIdParam=${viewPickProduct.productId}&shelfIdParam=${viewPickProduct.shelfId}" />编辑上架檔</a>
					</td>				
		 		 </tr>             
				</c-rt:forEach>
		</tbody>
	</table>
	<br />
	<s:select id="productAttribute" name="productAttribute" list="attributeMenu.options" listKey="key"  listValue="value.name" headerKey="" headerValue="---请选择销售状态---"/>
	<input type="submit" value="批次修改"/>	
</s:form>
<yaodian100:pageutil link="search.do${queryString}" pagerObj="${pager}" />
